package com.hj.springframework3.aop;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author : hujing
 * @Date: 2025/7/8 14:53
 * @Description:
 */
public class PoliteInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(Object bean, Method method, Object[] args) throws Throwable {
        // 修改标记了@Polite的方法返回值:
        if (method.getAnnotation(Polite.class)!= null){
            String result = (String) method.invoke(bean, args);
            if (result.endsWith(".")){
                result = result.substring(0,result.length()-1)+"!";
            }
            return result;
        }
        return method.invoke(bean,args);
    }
}
